package view;

import model.Holder;

import com.VanDoren.ArgusV2.R;

import controller.SystemController;
import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.SurfaceHolder;
import android.widget.RelativeLayout;

public class Scanner extends Activity 
{
	private static final String TAG = Scanner.class.getSimpleName();
	
	private SystemController _controller;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		Log.d(TAG, "OnCreate()");
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_scanner);
		
		_controller = new SystemController(this);
	}
	
	@Override
	protected void onResume() 
	{
		Log.d(TAG, "OnResume()");
		super.onResume();
		_controller.resumeCamera();
	}
	
	@Override
    protected void onPause() 
	{
		Log.d(TAG, "OnPause()");
	    super.onPause();
	    RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
	    mainLayout.removeViewsInLayout(1, mainLayout.getChildCount()-1);
	    _controller.stopCamera();
	}
	
	@Override
	protected void onStop() {
		Log.d(TAG, "OnStop()");
		super.onStop();
		onPause();
	}
	
	public void startCamera(SurfaceHolder holder)
	{
		Log.d(TAG, String.format("startPreview()"));
		_controller.startCamera(holder);
	}

	public void addNewHolderView(Holder holder) 
	{
		RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
		
		MachineView view = new MachineView(this);
		
		mainLayout.addView(view);
		holder.addObserver(view);
	}
	
	
}
